home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Tool Chest / Dev.CD Feb 97 TC.toast / Tool Chest / Development Tools & Languages / HyperCard Related / APDA HyperCard Toolkits / AppleTalk ToolKit / NBP / NBPConfirmName.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-07  |  4.9 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*******************************************************************\
  2. *    file:         NBPConfirmName.c                                    *
  3. *    version:    1.06ß                                                *
  4. *                                                                     *
  5. * Confirm an entity by its name, type and zone.  This routine is     *
  6. * provided for completeness.  ATSend automatically confirms an        *
  7. * entity before sending the message.                                *
  8. * -----------------------------------------------------------------    *
  9. * By:    Donald Koscheka                                                *
  10. * Date:    6-Oct-87                                                    *
  11. * ©    Copyright 1987, Apple Computer, Inc.                            *
  12. *    All Rights Reserved                                                *
  13. *                                                                    *
  14. * -----------------------------------------------------------------    *
  15. *                        Modification History                        *
  16. * -----------------------------------------------------------------    *
  17. *  Date           | By    |                     Description                    *
  18. * -----------------------------------------------------------------    *
  19. *  6-Oct-87    | DK    | file created                                    *
  20. *  5-Nov-87    | DK    | added return result                            *
  21. * 14-Jan-87    | DK    | modified to reflect decoupling of NBP & ATP    *
  22. * 22-Feb-88 | DK    | Move all locked handles high                    *
  23. * -----------------------------------------------------------------    *
  24. \*******************************************************************/
  25.  
  26. /*******************************************************************\
  27.                             Build Sequence
  28.     
  29. C -q2 -g -o "{hpo}"NBPConfirmName.c.o "{nbp}"NBPConfirmName.c
  30.     link  -sn Main=NBPConfirmName -sn STDIO=NBPConfirmName ∂
  31.          -sn INTENV=NBPConfirmName -rt XFCN=301 ∂
  32.          -m NBPCONFIRMNAME ∂
  33.          "{hpo}"NBPCONFIRMNAME.c.o  "{hpo}"atalkxcmd.c.o "{hpo}"xcmdutils.c.o ∂
  34.          "{CLibraries}"CInterface.o ∂
  35.          "{Libraries}"Interface.o ∂
  36.          -o "{hp}"HyperPeople
  37.  
  38. \*******************************************************************/
  39.  
  40. #include <Types.h>
  41. #include <Memory.h>
  42. #include <Resources.h>
  43. #include <OSUtils.h>
  44. #include <appleTalk.h>
  45. #include <HyperXCmd.h>
  46. #include <atalkXCMD.h>
  47. #include <XCMDUtils.h>
  48.  
  49. pascal void NBPConfirmName( paramPtr )
  50.     XCmdBlockPtr    paramPtr;
  51. /**********************************
  52. * ATConfirm
  53. *
  54. * In:    ParamPtr->params[0] = entityName 
  55. *        ParamPtr->params[1] = entityType
  56. *        ParamPtr->params[2] = entityZone
  57. *        ParamPtr->params[3] = count
  58. *        ParamPtr->params[4] = interval
  59. *
  60. * Out:    True if entity still visible,
  61. *        false otherwise.
  62. *
  63. * Defaults:
  64. *        Type    = 'HyperPeople'
  65. *        Zone     = '*'
  66. *        count    = 2
  67. *        interval= 8
  68. **********************************/
  69. {
  70.     short         total         = 0;
  71.     short        nextentity     = 1;
  72.     short        found         = 0;
  73.     short        result;
  74.     short        count, interval;
  75.     char        theName[34], theType[34], theZone[34];
  76.     char        namestr[100], typestr[34], zonestr[34];
  77.     long        temp;
  78.     char        **strH;
  79.     Handle        entityType = nil;
  80.     EntityName     eName;
  81.     AddrBlock     eAddr;    
  82.     NBPBlock    *nbp;
  83.     
  84.     nbp = (NBPBlock *)RetrieveHandle( paramPtr, GLOBALNBPDATA );
  85.     if( !nbp ){
  86.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  87.         return;
  88.     }
  89.  
  90.     if( paramPtr->params[0] == nil ){
  91.         /*** can't confirm the name if no name given ***/
  92.         paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  93.         return;
  94.     }
  95.     strcopy( theName, *(paramPtr->params[0]) );
  96.     
  97.     if( !paramPtr->params[1] ){    /*** type not specified ***/
  98.         if( entityType = GetResource('STR ', EntityTypeStr ) ){
  99.             pStrCopy( *entityType, theType );
  100.             p2cstr( theType );
  101.         }
  102.         else{
  103.             paramPtr->returnValue = ErrorReturn( DEFAULT_ERROR );
  104.             return;
  105.         }
  106.     }
  107.     else strcopy( theType, *(paramPtr->params[1]) );
  108.     
  109.     if( !paramPtr->params[2] ){    /*** zone not specified ***/
  110.         theZone[0] = '*';
  111.         theZone[1] = '\0';
  112.     }
  113.     else
  114.         strcopy( theZone, *(paramPtr->params[2]) );
  115.  
  116.     
  117.     if( paramPtr->params[3] ){    
  118.         HLock( paramPtr->params[3] );
  119.         c2pstr( *(paramPtr->params[3] ) );
  120.         count = (short)StrToNum( paramPtr, *(paramPtr->params[3]) );
  121.         HUnlock( paramPtr->params[2] );
  122.     }
  123.     else
  124.         count = 2;    
  125.     
  126.     if( paramPtr->params[4] ){    
  127.         HLock( paramPtr->params[4] );
  128.         c2pstr( *(paramPtr->params[4] ) );
  129.         interval = (short)StrToNum( paramPtr, *(paramPtr->params[4]) );
  130.         HUnlock( paramPtr->params[4] );
  131.     }
  132.     else
  133.         interval = 8;
  134.  
  135.     total     = nbp->EntCount;
  136.  
  137.     /*** scan the entity list until we find a match or scan past all entities. ***/
  138.     while( !found ){
  139.      found = ExtractName(  nbp, nextentity, &eName, &eAddr );
  140.          pStrCopy( &eName.objStr, namestr );
  141.         p2cstr( namestr );
  142.          pStrCopy( &eName.typeStr, typestr );
  143.         p2cstr( typestr );
  144.          pStrCopy( &eName.zoneStr, zonestr );
  145.         p2cstr( zonestr );
  146.  
  147.         if(    (!strCMP( theName, namestr )) &&
  148.             (!strCMP( theType, typestr )) &&
  149.             (!strCMP( theZone, zonestr ))
  150.           ){
  151.               /*** need to compress the string into an entityName ***/
  152.             c2pstr( namestr );
  153.             c2pstr( typestr );
  154.             c2pstr( zonestr );
  155.             
  156.             temp = (long)namestr[0] + 1;
  157.             BlockMove( typestr, namestr+temp, (long)*typestr+1 );
  158.             temp += (long)typestr[0] + 1;
  159.             BlockMove( zonestr, namestr+temp, (long)*zonestr+1 );
  160.             
  161.             found = ConfirmName( nbp, namestr, &eAddr, 2, 8);
  162.             break;
  163.         }
  164.         else{
  165.             ++nextentity;
  166.             found = 0;
  167.             if( nextentity > total )
  168.                 break;
  169.         }
  170.     }
  171.     strH = NewHandle( 8 );
  172.     MakeAnswer( found, *strH );
  173.     paramPtr->returnValue = strH;
  174. }
  175.